const fs = require('fs')
// 为了解决回调地狱,resolve,reject也是方法。resolve和reject是形参，可以随意写
function promise1() {
    return new Promise((resolve, reject) => {
        fs.readFile('test1.txt', 'utf8', (error, data) => {
            if (error != null) {
                /* console.log(error);
                return */
                // 用promise就这么写。交给catch方法处理
                reject(error)
            }
            console.log('读取成功！');
            resolve(data)
        })
    })
}
function promise2() {
    return new Promise((resolve, reject) => {
        fs.readFile('test2.txt', 'utf8', (error, data) => {
            if (error != null) {
                /* console.log(error);
                return */
                // 用promise就这么写。交给catch方法处理
                reject(error)
            }
            console.log('读取成功！');
            resolve(data)
        })
    })
}
function promise3() {
    return new Promise((resolve, reject) => {
        fs.readFile('test3.txt', 'utf8', (error, data) => {
            if (error != null) {
                /* console.log(error);
                return */
                // 用promise就这么写。交给catch方法处理
                reject(error)
            }
            console.log('读取成功！');
            resolve(data)
        })
    })
}
// 这个也是形参，也可以随意写
promise1().then((res1) => {
    console.log(res1);
    return promise2()
}).catch(err => {
    console.log(err);
})
    .then(res2 => {
        console.log(res2);
        return promise3()
    })
    .then(res3 => {
        console.log(res3);

    })
